package com.zhang.demo.presenter

import android.os.Handler
import android.os.Looper
import com.zhang.demo.contract.FileView
import com.zhang.demo.model.db.DBManager
import com.zhang.demo.utils.ThreadManager
import javax.inject.Inject

/**
 * Created by zhangke on 2020/8/21 22:15
 * E-Mail Address：2426017569@qq.com
 */
 class FilePresenter @Inject constructor (var dbManager: DBManager): BasePresenter<FileView>() {

    fun loadData() {
        ThreadManager.getInstance().execute(Runnable {
            if ( dbManager.isFileEmpty()){
                val assetsData = dbManager.loadAssetsData()
                dbManager.insertFile(assetsData)
            }
            val fileList = dbManager.getFileList()
            Handler(Looper.getMainLooper()).post {
                mvpView?.refresh(fileList)
            }
        })

    }

    fun removeFile(fid: Long) {
        dbManager.deleteFile(fid)
    }
}